package com.china08.yxyapi.api.home.kecheng.cloud;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.entity.db.lessons.cloud.YxyLessonsCloudCatalog;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.repository.db.lesson.YxyLessonsCloudCatalogRepository;

/****
 * 
 * @annotation :云课程--子目录查询
 * @author :yaoguanglin
 */
@CrossOrigin
@RestController
public class KechengCloudNextCatalogSrhController extends YxyApiBaseController {

    @Autowired
    private YxyLessonsCloudCatalogRepository yxyLessonsCloudCatalogRepository;

    @RequestMapping(value = "/api_yw/home/kecheng/cloud/next/catalog/srh", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public List<RespModel> precess(HttpServletRequest request, HttpServletResponse response,
            @RequestBody(required = false) ReqModel reqModel) {

        String schoolId = getProfile(request, response).getSchoolId();

        List<YxyLessonsCloudCatalog> list = yxyLessonsCloudCatalogRepository
                .findByPidOrderByOrderNumAscCreatedDateAsc(reqModel.id);
        List<RespModel> respModels = new ArrayList<KechengCloudNextCatalogSrhController.RespModel>();

        if (list != null && list.size() > 0) {
            for (YxyLessonsCloudCatalog yxyLessonsCloudCatalog : list) {
                RespModel model = new RespModel();
                model.id = yxyLessonsCloudCatalog.getId();
                model.name = yxyLessonsCloudCatalog.getName();
                model.pid = yxyLessonsCloudCatalog.getPid();
                model.level = yxyLessonsCloudCatalog.getLevel();
                respModels.add(model);
            }

        }

        return respModels;
    }

    protected static class ReqModel extends YxyApiReqModel {
        // 目录ID
        public String id;
    }

    protected static class RespModel extends YxyApiRespModel {
        // 目录名称
        public String name;
        // 目录ID
        public String id;
        // 父级目录ID
        public String pid;
        // 目录等级
        public Integer level;
    }
}
